package com.base.myproject.client.busi.system;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BaseStoreEvent;
import com.base.myproject.client.busi.BaseStoreListener;
import com.base.myproject.client.busi.JDBCModelData;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseBusiLeftPanel;
import com.base.myproject.client.ui.BaseFormPanel;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.BaseSerchHtml;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.KeyListener;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.layout.RowData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.user.client.Event;

public class CCODE extends BaseJDBCPanel {
	static BaseStore<JDBCModelData> store = null;

	public CCODE() {
		super();
		init();
	}

	public void init() {

		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);  
	    centerData.setMargins(new Margins(5, 5, 0, 0));  
	this.add(initWeiget(),centerData);

	}

	public ContentPanel initWeiget() {
		// ----

		// ----
		ContentPanel panel = new ContentPanel();
		panel.setLayout(new BorderLayout());
		BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 150);
		westData.setSplit(true);
		westData.setCollapsible(true);
		westData.setMargins(new Margins(0));
		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
		centerData.setMargins(new Margins(5, 0, 5, 0));

		panel.add(CreateCcodeLeftPanel(), westData);

		TabPanel tabpanel = new TabPanel();

		tabpanel.setWidth(450);
		tabpanel.setHeight(450);
		tabpanel.setAutoHeight(true);
		TabItem normal = new TabItem("基本信息");
		normal.add(CreateCCodeDetailPanel());
		
		
		 ContentPanel branchorg = new ContentPanel();//createCcodebranchorgaddPanel
		 TabItem bangogndizhi = new TabItem("办公地点和分支机构");
		    
		    branchorg.setHeight(400);
		    branchorg.setHeaderVisible(false);
		    branchorg.setLayout(new RowLayout(Orientation.VERTICAL));
		    branchorg.add(createOfficePanel(),new RowData(1, 0.5));
		   branchorg.add(createCcodebranchorgaddPanel(),new RowData(1, 0.5));
		   bangogndizhi.add(branchorg);
		   
		   TabItem lianxiren = new TabItem("联系人信息");
		   lianxiren.add(createLinkManPanel());
		   
		   final TabItem searchframe = new TabItem("查询相关信息");
		   searchframe.setAutoHeight(true);
		   final BaseSerchHtml bsh = new BaseSerchHtml();
		   searchframe.add(bsh.getSearchFrame());
		   searchframe.addListener(Events.Select, new Listener(){

			@Override
			public void handleEvent(BaseEvent be) {
				bsh.SearchHtml(store.getValue("cname")==null?"":store.getValue("cname").toString());
			
			}});
		   /**
		    * store 换行的时候进行关键字的搜索
		    */
		   store.addBaseStoreListener(BaseStoreEvent.EventType.ROW_CHANGED, new BaseStoreListener()
		   {

			@Override
			public void BaseStoreEventHandle(BaseStoreEvent evt) {
				if (evt.getEventType() == BaseStoreEvent.EventType.ROW_CHANGED) {
					
					if(searchframe.isVisible())
					{
						bsh.SearchHtml(store.getValue("cname")==null?"":store.getValue("cname").toString());
					}
				}
				
			}

			@Override
			public void onBrowserEvent(Event event) {
				// TODO Auto-generated method stub
				
			}
		   });
		   tabpanel.add(normal);
		   tabpanel.add(bangogndizhi);
		   tabpanel.add(lianxiren);
		   tabpanel.add(searchframe);
			 
		panel.add(tabpanel, centerData);

		registerMainStore(store);
		registerStore(store);
		return panel;
	}

	/*
	 * 客户管理左边带搜索的界面
	 */

	public ContentPanel CreateCcodeLeftPanel() {
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		ColumnConfig cname = new ColumnConfig("cname", "客户名称", 200);
		TextField<String> gnametext = new TextField<String>();
		cname.setEditor(new CellEditor(gnametext));
		columns.add(cname);
		
		ColumnConfig ccode = new ColumnConfig("ccode", "客户编码", 200);
		TextField<String> ccodetext = new TextField<String>();
		ccode.setEditor(new CellEditor(ccodetext));
		
//		ccodetext.addListener(Events.Change,new  Listener<FieldEvent>(){
//
//			@Override
//			public void handleEvent(FieldEvent be) {
//				// TODO Auto-generated method stub
//				System.out.println("_____________________________");
//			}
//			
//		});
		columns.add(ccode);
		DateField dateField = new DateField();

		ColumnModel cm = new ColumnModel(columns);

		// --set modetype
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("ccode");
		type.addField("cname");
		// type.addField("Phone");
		// type.addField("imagepath");
		StoreInfo info = new StoreInfo();
		info.setTablename("ccode");
		info.setSql("select * from ccode");
		info.setKeyname(new String[] { "ccode" });
		BaseBusiLeftPanel basbusileftpanel = new BaseBusiLeftPanel(columns,
				type, info);
		store = basbusileftpanel.getStore();
		

		basbusileftpanel.getGrid().setAutoExpandColumn("cname");
		setMaincomponent(basbusileftpanel.getGrid());
		return basbusileftpanel.getPanel();
	}

	/**
	 * 客户资料
	 * 
	 * @return
	 */
	private LayoutContainer CreateCCodeDetailPanel() {
		LayoutContainer main = new LayoutContainer();
		TableLayout tl = new TableLayout(2);

		main.setLayout(new TableLayout(2));
		BaseFormPanel leftpanel = new BaseFormPanel(store);
		leftpanel.setLayout(new FormLayout());
		FormData fd = new FormData(200, 30);
		leftpanel.setHeaderVisible(false);
		leftpanel.setBodyBorder(false);

		BaseFormPanel rightpanel = new BaseFormPanel(store);
		rightpanel.setBodyBorder(false);
		rightpanel.setHeaderVisible(false);

		TextField<String> ccode = new TextField<String>();
		ccode.setName("ccode");
		ccode.setAllowBlank(false);
		ccode.setFieldLabel("编码");

		TextField<String> name = new TextField<String>();
		name.setName("cname");
		name.setAllowBlank(false);
		name.setFieldLabel("名称");

		TextField<String> shortcode = new TextField<String>();
		shortcode.setName("shortcode");
		shortcode.setFieldLabel("简码");
		TextField<String> ccodesource = new TextField<String>();
		ccodesource.setName("ccodesource");
		ccodesource.setFieldLabel("客户来源");

		TextField<String> ncode = new TextField<String>();
		ncode.setName("ncode");
		ncode.setFieldLabel("国别");

		TextField<String> httpurl = new TextField<String>();
		httpurl.setName("httpurl");
		httpurl.setFieldLabel("网址");

		DateField setupdate = new DateField();
		setupdate.setName("setupdate");
		setupdate.setFieldLabel("成立时间");
		TextField<String> registercapital = new TextField<String>();
		registercapital.setName("registercapital");
		registercapital.setFieldLabel("注册资金");

		TextField<String> employeenum = new TextField<String>();
		employeenum.setName("employeenum");
		employeenum.setFieldLabel("雇用人数");

		TextField<String> branchorgnum = new TextField<String>();
		branchorgnum.setName("branchorgnum");
		branchorgnum.setFieldLabel("分支机构数");

		TextField<String> artperson = new TextField<String>();
		artperson.setName("artperson");
		artperson.setFieldLabel("法人代表");

		TextField<String> taxno = new TextField<String>();
		taxno.setName("taxno");
		taxno.setFieldLabel("税务登记号");

		TextField<String> partner = new TextField<String>();
		partner.setName("partner");
		partner.setFieldLabel("合伙人");

		/*
		 * TextField<String> artno = new TextField<String>();
		 * artno.setName("artno"); artno.setFieldLabel("企业代码");
		 */

		TextField<String> comholsdatedesc = new TextField<String>();
		comholsdatedesc.setName("comholsdatedesc");
		comholsdatedesc.setFieldLabel("公司特殊假日");

		BaseGrid gudong = CreateCCodeGudongPanel();
		gudong.setAutoHeight(true);
		gudong.setAutoWidth(true);
		leftpanel.add(ccode, fd);
		rightpanel.add(name, fd);
		leftpanel.add(shortcode, fd);
		rightpanel.add(ccodesource, fd);
		leftpanel.add(httpurl, fd);
		rightpanel.add(setupdate, fd);
		leftpanel.add(registercapital, fd);
		rightpanel.add(employeenum, fd);
		leftpanel.add(branchorgnum, fd);
		rightpanel.add(artperson, fd);
		leftpanel.add(taxno, fd);
		rightpanel.add(partner, fd);
		leftpanel.add(comholsdatedesc, fd);

		TableData td = new TableData();
		td.setColspan(1);
		td.setRowspan(1);
		// 对齐方式
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);
		// rightpanel.add(gudong,td2);
		leftpanel.inited();
		rightpanel.inited();
		FieldSet fieldSet = new FieldSet();
		fieldSet.setHeading("股东占股比例");
		fieldSet.add(gudong);
		main.add(leftpanel, td);
		main.add(rightpanel, td);
		main.add(fieldSet, td);
		return main;
	}

	/**
	 * 客户的股东和比例
	 * 
	 * @return
	 */

	private BaseGrid CreateCCodeGudongPanel() {

		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		ColumnConfig gudongmingcheng = new ColumnConfig("gudong", "股东名称", 100);
		TextField<String> gudongmingchengtext = new TextField<String>();
		gudongmingcheng.setEditor(new CellEditor(gudongmingchengtext));
		columns.add(gudongmingcheng);
		ColumnConfig rate = new ColumnConfig("rate", "占股比例", 100);
		TextField<String> ratetext = new TextField<String>();
		rate.setEditor(new CellEditor(ratetext));
		columns.add(rate);

		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");

		type.addField("gudong");
		type.addField("rate");

		StoreInfo info = new StoreInfo();

		info.setTablename("ccodegudong");
		info.setSql("select * from ccodegudong");
		info.setParent(store);// 关联主表
		info.setAutoinccolumn("idx"); // 自增字段，如果子表一定需要
		info.setLinkparentcolumns(new String[] { "ccode" }); // 关联主表字段
		info.setKeyname(new String[] { "ccode", "idx" }); // 主键
		
		BaseStore gudong = new BaseStore<JDBCModelData>(type, info);
		gudong.setName("gudong");
		ColumnModel cm = new ColumnModel(columns);
		BaseGrid gudonggrid = new BaseGrid(gudong, cm);

		cbs.setSelectionMode(SelectionMode.SINGLE);

		gudonggrid.setSelectionModel(cbs);
		gudonggrid.setAutoHeight(true);
		gudonggrid.setAutoWidth(true);

		registerStore(gudong);
		return gudonggrid;
	}

	// 办公地址信息
	public ContentPanel createOfficePanel() {
		ContentPanel panel = new ContentPanel();
		panel.setSize(400, 400);
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		ColumnConfig ccode = new ColumnConfig("ccode", "ccode", 100);
		 columns.add(ccode);

		ColumnConfig column = new ColumnConfig("addrtype", "地址类型", 100);
		TextField<String> text = new TextField<String>();
		column.setEditor(new CellEditor(text));
		columns.add(column);
		ColumnConfig addr = new ColumnConfig("addr", "街道", 100);
		TextField<String> addrtext = new TextField<String>();
		addr.setEditor(new CellEditor(addrtext));
		columns.add(addr);

		ColumnConfig ncode = new ColumnConfig("ncode", "国别地区", 100);
		TextField<String> ncodetext = new TextField<String>();
		ncode.setEditor(new CellEditor(ncodetext));
		columns.add(ncode);

		ColumnConfig fax = new ColumnConfig("fax", "传真", 100);
		TextField<String> faxtext = new TextField<String>();
		fax.setEditor(new CellEditor(faxtext));
		columns.add(fax);

		ColumnModel cm = new ColumnModel(columns);

		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");

		type.addField("ccode", "ccode");
		type.addField("idx");
		type.addField("addrtype");
		type.addField("addr");
		type.addField("ncode");
		type.addField("fax");
		StoreInfo info = new StoreInfo();

		info.setTablename("ccodeofficeaddress");
		info.setSql("select * from ccodeofficeaddress");
		info.setParent(store);
		info.setAutoinccolumn("idx");
		info.setLinkparentcolumns(new String[] { "ccode" });
		info.setKeyname(new String[] { "ccode", "idx" });
		
		BaseStore<JDBCModelData> officestore = new BaseStore<JDBCModelData>(
				type, info);
		officestore.setName("ccodeofficeaddress");
		BaseGrid officegrid = new BaseGrid(officestore, cm);
		cbs.setSelectionMode(SelectionMode.SINGLE);
		officegrid.setSelectionModel(cbs);
		// officegrid.setAutoExpandColumn("ccode");
		// panel.setLayout(new BorderLayout());
		panel.setLayout(new FitLayout());
		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
		centerData.setMargins(new Margins(0));
		panel.add(officegrid);
		// officegrid.set
		
		registerStore(officestore);
		return panel;
	}

	// 分支机构
	public ContentPanel createCcodebranchorgaddPanel() {
		ContentPanel panel = new ContentPanel();
		panel.setSize(400, 400);
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();

		 ColumnConfig ccode = new ColumnConfig("ccode", "ccode", 100);
		 columns.add(ccode);

		ColumnConfig column = new ColumnConfig("orgname", "分支机构名称", 100);
		TextField<String> text = new TextField<String>();
		column.setEditor(new CellEditor(text));
		columns.add(column);
		ColumnConfig gname = new ColumnConfig("addr", "街道", 100);
		TextField<String> gnametext = new TextField<String>();
		gname.setEditor(new CellEditor(gnametext));
		columns.add(gname);

		ColumnConfig ncode = new ColumnConfig("ncode", "国别地区", 100);
		TextField<String> ncodetext = new TextField<String>();
		gname.setEditor(new CellEditor(ncodetext));
		columns.add(ncode);

		ColumnConfig fax = new ColumnConfig("fax", "传真", 100);
		TextField<String> faxtext = new TextField<String>();
		gname.setEditor(new CellEditor(faxtext));
		columns.add(fax);
		ColumnConfig telephone = new ColumnConfig("telephone", "电话", 100);
		TextField<String> telephonetext = new TextField<String>();
		gname.setEditor(new CellEditor(telephonetext));
		columns.add(telephone);
		ColumnConfig mobil = new ColumnConfig("mobil", "电话", 100);
		TextField<String> mobiltext = new TextField<String>();
		gname.setEditor(new CellEditor(mobiltext));
		columns.add(mobil);
		ColumnConfig postcode = new ColumnConfig("postcode", "邮编", 100);
		TextField<String> postcodetext = new TextField<String>();
		gname.setEditor(new CellEditor(postcodetext));
		columns.add(postcode);
		ColumnModel cm = new ColumnModel(columns);

		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("ccode", "ccode");
		type.addField("orgname");
		
		type.addField("addr");
		type.addField("ncode");
		type.addField("idx");
		type.addField("fax");
		type.addField("telephone");
		type.addField("mobil");
		type.addField("postcode");
		StoreInfo info = new StoreInfo();

		info.setTablename("ccodebranchorgadd");
		info.setSql("select * from ccodebranchorgadd");
		info.setParent(store);
		info.setAutoinccolumn("idx");
		info.setLinkparentcolumns(new String[] { "ccode" });
		info.setKeyname(new String[] { "ccode", "idx"});
		
		BaseStore<JDBCModelData> branchorgadd = new BaseStore<JDBCModelData>(
				type, info);
		branchorgadd.setName("ccodebranchorgadd");
			BaseGrid branchorgaddstore = new BaseGrid(branchorgadd, cm);
		// officegrid.setAutoExpandColumn("ccode");
		// panel.setLayout(new BorderLayout());
		panel.setLayout(new FitLayout());
		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
		centerData.setMargins(new Margins(0));
		panel.add(branchorgaddstore);
		registerStore(branchorgadd);
		return panel;
	}
	
	 /**
	  * 联系人
	  * @return
	  */
	 public ContentPanel createLinkManPanel() {  
		 
				 
		   CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
			   
	
		   List<ColumnConfig> columns = new ArrayList<ColumnConfig>();  
		    columns.add(cbs.getColumn());
	
		  
		     ColumnConfig lname = new ColumnConfig("lname", "姓名", 80); 
		    TextField<String> text = new TextField<String>(); 
		    lname.setEditor(new CellEditor(text));
		    columns.add(lname);
		    
		    ColumnConfig dept = new ColumnConfig("dept", "部门", 80); 
		    TextField<String> depttext = new TextField<String>(); 
		    dept.setEditor(new CellEditor(depttext));
		    columns.add(dept);
		 
		    ColumnConfig headship = new ColumnConfig("headship", "职务", 80); 
		    TextField<String>headshiptext = new TextField<String>(); 
		    headship.setEditor(new CellEditor(headshiptext));
		    columns.add(headship);
		    
		 
		    ColumnConfig passportcode = new ColumnConfig("passportcode", "护照号", 80); 
		    TextField<String> passportcodetext = new TextField<String>(); 
		    passportcode.setEditor(new CellEditor(passportcodetext));
		    columns.add(passportcode);
		   
		    
			 
		    ColumnConfig postcode1 = new ColumnConfig("postcode", "邮编", 80); 
		    TextField<String> postcodetext = new TextField<String>(); 
		    postcode1.setEditor(new CellEditor(postcodetext));
		    columns.add(postcode1);
		    ColumnModel cm = new ColumnModel(columns);  
		   
		 

		 ModelType type = new ModelType();  
		 type.setRoot("records") ;  
		    type.setRecordName("record");  
		    type.setTotalName("totle");
		    type.addField("ccode", "ccode");  
		    
		    type.addField("lname");  
		    type.addField("headship");  
		    type.addField("dept");  
			type.addField("idx");
		    type.addField("addr");  
		    type.addField("headship");  
		    type.addField("passportcode");  
		    
		    type.addField("postcode");
		    type.addField("telephone"); 
		    type.addField("mobil"); 
		    type.addField("privatemobil");  
		    type.addField("fax"); 
		    type.addField("addrtype"); 
		    
		    StoreInfo info= new StoreInfo();
		    
		    info.setTablename("ccodelinkman_info");
		    info.setSql("select * from ccodelinkman_info");
		    info.setParent(store);
		    info.setAutoinccolumn("idx");
		    info.setLinkparentcolumns(new String[]{"ccode"});
		    info.setKeyname(new String[]{"ccode","idx"});
			
  BaseStore<JDBCModelData>  branchorgadd = new BaseStore<JDBCModelData>(type,info);
		    branchorgadd.setName("ccodelinkman_info");
		    BaseGrid branchorgaddgrid=new BaseGrid(branchorgadd, cm);
		    cbs.setSelectionMode(SelectionMode.SINGLE);
		    branchorgaddgrid.setSelectionModel(cbs);
		    //   officegrid.setAutoExpandColumn("ccode");  
		  //  panel.setLayout(new BorderLayout());
		    
		    //----------------------------
		    final BaseFormPanel formpanel = new BaseFormPanel(branchorgadd);  
		 
		  
		    TextField<String> branchtelephone = new TextField<String>();  
		    branchtelephone.setName("telephone");  
		    branchtelephone.setFieldLabel("办公电话"); 

		    formpanel.add(branchtelephone);  
		   final TextField<String> mobil = new TextField<String>();  
		    mobil.setName("mobil");  
		    mobil.setFieldLabel("移动电话");  
		    
		    formpanel.add(mobil);  
		  
		    final TextField<String>  privatemobil = new TextField<String> ();  
		    privatemobil.setName("privatemobil");  
		    privatemobil.setFieldLabel("私人电话");  
		    formpanel.add(privatemobil);  
		  
		    privatemobil.addKeyListener(new KeyListener(){
		    	  public void componentKeyUp(ComponentEvent event) {
		    		  mobil.setValue(privatemobil.getValue());
		    	  }
		    });
		    
		    
		    TextField<String>  fax = new TextField<String> ();  
		    fax.setName("fax");  
		    fax.setFieldLabel("传真");  
		   
		    formpanel.add(fax);  
		    
		    TextField<String>  addrtype = new TextField<String> ();  
		    addrtype.setName("addrtype");  
		    addrtype.setFieldLabel("地址类型");  
		   
		    formpanel.add(addrtype);  
		    
		   final TextField<String>  postcode = new TextField<String> ();  
		    postcode.setName("postcode");  
		    postcode.setFieldLabel("邮编");  
		    
		    formpanel.add(postcode);  
		    
		    TextField<String>  addr = new TextField<String> ();  
		    addr.setName("addr");  
		    addr.setFieldLabel("通讯地址");  
		   
		    formpanel.add(addr); 
		   
		    formpanel.setScrollMode(Scroll.AUTO);
		    formpanel.inited();

		
		    //设置联系人界面上半部分的布局
			LayoutContainer top = new LayoutContainer();
			TableLayout tl = new TableLayout(2);
			top.setLayout(tl);
			TableData td = new TableData();
			td.setColspan(1);
			
			td.setRowspan(1);
			td.setVerticalAlign(VerticalAlignment.TOP);
//			TableData td2 = new TableData();
//			td2.setColspan(1);
//			td2.setRowspan(1);
			
//		    branchorgaddgrid.setSize(300, 200);
		 //   branchorgaddgrid.setAutoWidth(true);
			branchorgaddgrid.setWidth(420);
		    branchorgaddgrid.setAutoHeight(true);
		   // formpanel.setSize(300, 380);
		    formpanel.setHeaderVisible(false);
		   
			top.add(branchorgaddgrid,td);
			top.add(formpanel,td);
			
		    //----------------家庭成员ccodecustomersolicitude
		    
		   
			 List<ColumnConfig> customercolumns = new ArrayList<ColumnConfig>();  
			 
			  CheckBoxSelectionModel cbs2 = new CheckBoxSelectionModel();
			   
			  customercolumns.add(cbs2.getColumn());
			    ColumnConfig leaguertype = new ColumnConfig("leaguertype", "家庭成员", 80); 
			    TextField<String> leaguertext = new TextField<String>(); 
			    leaguertype.setEditor(new CellEditor(leaguertext));
			    customercolumns.add(leaguertype);
			    ColumnConfig leaguername = new ColumnConfig("leaguername", "姓名", 80); 
			    TextField<String> leaguernametext = new TextField<String>(); 
			    leaguername.setEditor(new CellEditor(leaguernametext));
			    customercolumns.add(leaguername);
		
			   
			    ColumnModel customercm = new ColumnModel(customercolumns);  
			    
			 
			 
			 ModelType customertype = new ModelType();  
			 customertype.setRoot("records");  
			 customertype.setRecordName("record");  
	
			 customertype.addField("ccode", "ccode");  
			 customertype.addField("leaguertype");  
			 customertype.addField("leaguername");  
			 customertype.addField("idx");
			 customertype.addField("birthday");
			 customertype.addField("commemorateday");
			 customertype.addField("religion");
			 customertype.addField("bekeenon");
			 customertype.addField("tourexperience");
			 customertype.addField("workexperience");
			 customertype.addField("occupation");
			 customertype.addField("workheadship");
			 customertype.addField("remark");
			 
			 
			 
			 
			     
			     
			    StoreInfo customerinfo= new StoreInfo();
			    
			    customerinfo.setTablename("ccodecustomersolicitude");
			    customerinfo.setSql("select * from ccodecustomersolicitude");
			    customerinfo.setParent(store);
			    customerinfo.setAutoinccolumn("idx");
			    customerinfo.setLinkparentcolumns(new String[]{"ccode"});
			    customerinfo.setKeyname(new String[]{"ccode","idx"});
				
			    BaseStore<JDBCModelData> customertypestore = new BaseStore<JDBCModelData>(customertype,customerinfo);
			   customertypestore.setName("ccodecustomersolicitude");
			    BaseGrid customertypegrid=new BaseGrid(customertypestore, customercm);
		    
			    cbs2.setSelectionMode(SelectionMode.SINGLE);
			    customertypegrid.setSelectionModel(cbs2);
		    //---------------------
		    //--	
			    BaseFormPanel formcustomerpanel = new BaseFormPanel(customertypestore);  
			    formcustomerpanel.setHeaderVisible(false);  
			  
			    TextField<String> birthdayc = new TextField<String>();  
			    birthdayc.setName("birthday");  
			    birthdayc.setFieldLabel("生日"); 
			    
			    formcustomerpanel.add(birthdayc);  
			  
			    TextField<String> commemorateday = new TextField<String>();  
			    commemorateday.setName("commemorateday");  
			    commemorateday.setFieldLabel("纪念日");  
			    
			    formcustomerpanel.add(commemorateday);  
			  
			    TextField religion = new TextField();  
			    religion.setName("religion");  
			    religion.setFieldLabel("信仰");  
			    formcustomerpanel.add(religion);  
			  
			    TextField bekeenon = new TextField();  
			    bekeenon.setName("bekeenon");  
			    bekeenon.setFieldLabel("主要爱好");  
			   
			    formcustomerpanel.add(bekeenon);  
			    
			    TextField tourexperience = new TextField();  
			    tourexperience.setName("tourexperience");  
			    tourexperience.setFieldLabel("旅游经历");  
			   
			    formcustomerpanel.add(tourexperience);  
			    
			    TextField workexperience = new TextField();  
			    workexperience.setName("workexperience");  
			    workexperience.setFieldLabel("工作经历");  
			    
			    formcustomerpanel.add(workexperience);  
			    
			    TextField occupation = new TextField();  
			    occupation.setName("occupation");   
			    occupation.setFieldLabel("职业");  
			   
			    formcustomerpanel.add(occupation);  
			    
			    TextField workheadship = new TextField();  
			    workheadship.setName("workheadship");   
			    workheadship.setFieldLabel("工作职位");  
			   
			    formcustomerpanel.add(workheadship);  
			    
			    TextField remark = new TextField();  
			    remark.setName("remark");  
			    remark.setFieldLabel("备注");  
			   
			    formcustomerpanel.add(remark);  
			    formcustomerpanel.setScrollMode(Scroll.AUTO);
			    formcustomerpanel.inited();
//			    FormBinding formcustomerBindings = new FormBinding(formcustomerpanel, true);  
//			    formcustomerBindings.setStore(customertypestore); 
			    
			   
			    //--end
		
		   
		    ContentPanel panel = new ContentPanel();
		  
		    panel.setLayout(new  TableLayout(2));
		    panel.setHeaderVisible(false);

		    TableData td1= new TableData();
		    td1.setColspan(2);
		    

		   
		
		
		  
		 //   panel.add(formpanel,td2);
		    customertypegrid.setAutoHeight(true);
//		    customertypegrid.setAutoWidth(true);
		    customertypegrid.setWidth(420);
		  //  formcustomerpanel.setSize(300, 300);

			TableData td2 = new TableData();
			td2.setColspan(1);
			td2.setRowspan(1);
		
			LayoutContainer bottom = new LayoutContainer();
			
			TableLayout bottomtl = new TableLayout(2);
			bottom.setLayout(bottomtl);
			TableData bottomtd = new TableData();
			bottomtd.setVerticalAlign(VerticalAlignment.TOP);
			bottomtd.setColspan(1);
			bottomtd.setRowspan(1);

			
			
			bottom.add(customertypegrid,bottomtd);      
			bottom.add(formcustomerpanel,bottomtd);
			 FieldSet fieldset = new FieldSet();
			 fieldset.setHeading("联系人");
			 FieldSet fieldset2 = new FieldSet();
			 fieldset2.setHeading("联系人家庭成员信息");
			 fieldset.add(top);
			 fieldset2.add(bottom);
			 
			  panel.add(fieldset,td1);
			  panel.add(fieldset2,td1);
		    panel.setScrollMode(Scroll.AUTO);
		    panel.setAutoHeight(true);
		    panel.setAutoWidth(true);
		 return panel;
	 }

}
